package com.gadgets.framework.common.util;

/**
 * @author UncleXiu
 * @version V1.0.0
 * @data 2020-12-07
 *
 */
public class ExceptionUtil {

    @SuppressWarnings("unchecked")
    public static <T extends Throwable, Y extends Class<T>> T getRealException(Throwable exception, Y type){
        if(exception.getClass().getName().equals(type.getName())){
            return (T) exception;
        }else {
            Throwable cause = exception.getCause();
            if(cause==exception){
                return null;
            }
            return getRealException(cause,type);
        }
    }

}
